from ..models.setting.rp_price_adjust_rule import ADJUST_RULE


class PriceAdjustRuleFC(object):
    """
    Model:
        满足调价的所有算法逻辑

    Param:
        - env: odoo env

    Function:
        - get_adjusted_price: 获取调后价格
    """

    def __init__(self, env):
        self.env = env

    def get_adjusted_price(self, tag_price, price_adjust_rule):
        """
        根据定价和给定的调价模板，计算最后调整后的价格

        :param tag_price: 定价(float)
        :param price_adjust_rule: (rp.price.adjust.rule)

        @return adjusted_price
        """
        if tag_price and price_adjust_rule:
            adjusted_price = 0.0

            if price_adjust_rule.rule == ADJUST_RULE[0][0]:
                adjusted_price = price_adjust_rule.changed_price
            elif price_adjust_rule.rule == ADJUST_RULE[1][0]:
                adjusted_price = tag_price + price_adjust_rule.fixed_float
            elif price_adjust_rule.rule == ADJUST_RULE[3][0]:
                adjusted_price = tag_price - price_adjust_rule.fixed_float
            elif price_adjust_rule.rule == ADJUST_RULE[2][0]:
                adjusted_price = tag_price * (1 + price_adjust_rule.rated_float)
            elif price_adjust_rule.rule == ADJUST_RULE[4][0]:
                adjusted_price = tag_price * (1 - price_adjust_rule.rated_float)

            return adjusted_price
        else:
            return 0.0
